package com.xy.tianyu.module.picture.adapter

import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.android.exoplayer2.C
import com.xy.tianyu.R
import com.xy.tianyu.module.picture.activity.PicSearchActivity
import com.xy.tianyu.module.picture.bean.S
import kotlinx.android.synthetic.main.fragment_pic_category_child.*

/**
 * @time 2020/10/13 15:59
 * @class 描述:
 */
class PicCategoryMoreTwoAdapter(layoutResId: Int, data:MutableList<S>):
    BaseQuickAdapter<S, BaseViewHolder>(layoutResId,data){
    override fun convert(holder: BaseViewHolder, item: S) {
        holder.setText(R.id.tv_cate,item.t)
        val list = item.s

        if (!list.isNullOrEmpty()){
            val mTvAll = holder.getView<TextView>(R.id.tv_cate_all)
            if (list.size<6){
                mTvAll.visibility = View.GONE
            }else{
                mTvAll.visibility = View.VISIBLE
            }
            val ryChild = holder.getView<RecyclerView>(R.id.ry_cate)
            ryChild.layoutManager = GridLayoutManager(context,2)
            val picCategoryMoreTwoChildAdapter = PicCategoryMoreTwoChildAdapter(R.layout.item_pic_cate_one,list)
            ryChild.adapter = picCategoryMoreTwoChildAdapter

            picCategoryMoreTwoChildAdapter.setOnItemClickListener(object :OnItemClickListener{
                override fun onItemClick(
                    adapter: BaseQuickAdapter<*, *>,
                    view: View,
                    position: Int
                ) {
                    PicSearchActivity.actionStart(context,list[position].t)
                }

            })
        }
    }
}